#pragma once

#include <memory>

#include <atlctrls.h>
#include <atlmisc.h>
#include <atlscrl.h>
#include <atlframe.h>
#include <atlwince.h>
#include <atlcrack.h>

#include "MainWndMode.h"
#include "MainWnd.h"
#include "ListModeController.h"

class MainWndListMode : public MainWndMode
{
public:

    MainWndListMode( MainWnd& window );

    BEGIN_MSG_MAP_EX(MainWndListMode)
        MESSAGE_HANDLER(WM_SIZE, OnSize)
        MESSAGE_RANGE_HANDLER(WM_KEYFIRST, WM_KEYLAST, OnKey)
        MSG_WM_LBUTTONDOWN(OnLButtonDown)
        MSG_WM_LBUTTONUP(OnLButtonUp)
		COMMAND_ID_HANDLER(ID_FILE_NEW, OnFileNew)
//        NOTIFY_CODE_HANDLER(NM_CLICK, OnItemClick)

        // REFLECT_NOTIFICATIONS
        {
            bHandled = TRUE;
            lResult = host.ReflectNotifications(uMsg, wParam, lParam, bHandled);
            if(bHandled)
                return TRUE;
        }

    END_MSG_MAP() 

    void RecalcLayout();

private:

    typedef std::auto_ptr<Command> CommandPtr;

//    void GoEditMode(  );

    void Initialize();

	LRESULT OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnItemClick(int item, LPNMHDR lpNMHDR, BOOL bHandled);
    void OpenItem(int item);

    LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnKey(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/);

    void OnLButtonDown( UINT, const CPoint& pt );
    void OnLButtonUp( UINT, const CPoint& pt );

    MainWnd & host;
    ListView & listView;
    ListModel & listModel;

    std::auto_ptr<ListModeController> controller;
};